﻿using HCQ2_Common.SQL;
using HCQ2_IDAL;
using HCQ2_Model;
using HCQ2_Model.SchoolClass;
using HCQ2_Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_DAL_MSSQL
{
    /// <summary>
    /// 班级
    /// </summary>
    public partial class T_ClassDAL: IT_ClassDAL
    {
        /// <summary>
        /// 获取班级列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public TableModel GetClassList(SchoolClassListQuery query)
        {
            StringBuilder where = new StringBuilder(4);
            if (!string.IsNullOrEmpty(query.schoolName)) {
                where.AppendFormat("schoolCode='{0}' and ", query.schoolName);
            }
            if (!string.IsNullOrEmpty(query.teacherName))
            {
                where.AppendFormat("teacherName like '%{0}%' and ", query.teacherName);
            }
            if (query.entranceYear != null)
            {
                where.AppendFormat("entranceYear={0} and ", query.entranceYear);
            }

            if (where.Length > 1) {
                where.Insert(0, " where ");
                where.Remove(where.Length-4,4);
            }

            string sql = string.Format("select * from T_Class {0}", where.ToString());

            var rowsData = SqlHelper.ExecutePageList<T_Class>(query.page,query.rows, "schoolName,entranceYear desc,className", sql);
            int countData = SqlHelper.GetCount(sql);

            return new TableModel()
            {
                rows = rowsData,
                total = countData
            };
        }
    }
}
